﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;
using HRM.DAL.Report;
using HRM.ReportManager;

namespace HRM.ReportAll
{
    public partial class rptSalaryReportUI : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadProject();
                Loadcatagory();

            }
        }
        private void Loadcatagory()
        {
            List<Catagory> catagories = new List<Catagory>();
            CatagoryManager manager = new CatagoryManager();
            catagories = manager.GetAllCatagories();
            ddempCatagory.DataTextField = "EmpCatagory";
            ddempCatagory.DataValueField = "Id";
            ddempCatagory.DataSource = catagories;
            ddempCatagory.DataBind();
            ddempCatagory.Items.Insert(0, "---Choose Any---");

        }
        private void LoadProject()
        {
            List<Project> projects = new List<Project>();
            ProjectManager manager = new ProjectManager();
            projects = manager.GetAllProjects();
            ddlEmpProject.DataTextField = "ProjectName";
            ddlEmpProject.DataValueField = "Id";
            ddlEmpProject.DataSource = projects;
            ddlEmpProject.DataBind();
            ddlEmpProject.Items.Insert(0, "---Choose Any---");

        }
        protected void ShowSalaryReportByProject(object o,EventArgs e)
        {
            Company company = new Company();
            company = company.GetCompanyInfo();
            List<SalaryReport> salaryReports=new List<SalaryReport>();
            RptSalaryManager manager=new RptSalaryManager();
            int projectId = Convert.ToInt32(ddlEmpProject.Value);
            salaryReports = manager.SalaryReportByProject(projectId);
            int i = 0;
            foreach (SalaryReport report in salaryReports)
            {
                salaryReports[i].Company = company.Name;
                salaryReports[i].Address = company.Address;
                i++;
            }
            SalaryReportByProject crtReport=new SalaryReportByProject();
            crtReport.SetDataSource(salaryReports);
            salaryViewer.ReportSource = crtReport;
        }

        protected void ShowAllEmployeeSalaryReport(Object o,EventArgs e)
        {
            Company company = new Company();
            company = company.GetCompanyInfo();
            List<SalaryReport> salaryReports = new List<SalaryReport>();
            RptSalaryManager manager = new RptSalaryManager();
            salaryReports = manager.AllEmployeeSalaryReport();
            int i = 0;
            foreach (SalaryReport report in salaryReports)
            {
                salaryReports[i].Company = company.Name;
                salaryReports[i].Address = company.Address;
                i++;
            }
            SalaryReportForAllEmployee crtReport = new SalaryReportForAllEmployee();
            crtReport.SetDataSource(salaryReports);
            salaryViewer.ReportSource = crtReport;
        }
        protected void ShowSalaryReportByEmpCatagory(object o,EventArgs e)
        {
            Company company = new Company();
            company = company.GetCompanyInfo();
            List<SalaryReport> salaryReports = new List<SalaryReport>();
            RptSalaryManager manager = new RptSalaryManager();
            int catId = Convert.ToInt32(ddempCatagory.Value);
            salaryReports = manager.SalaryReportByCatagory(catId);
            int i = 0;
            foreach (SalaryReport report in salaryReports)
            {
                salaryReports[i].Company = company.Name;
                salaryReports[i].Address = company.Address;
                i++;
            }
            SalaryReportByEmpCatagory crtReport = new SalaryReportByEmpCatagory();
            crtReport.SetDataSource(salaryReports);
            salaryViewer.ReportSource = crtReport;
        }

        protected void printReport_Click(object sender, EventArgs e)
        {
            SalaryReportByEmpCatagory crtReport = new SalaryReportByEmpCatagory();
            System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
            crtReport.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
            crtReport.PrintToPrinter(1, true, 1, 1);
        }

    }
}